<!-- TODO -->
<template>
    <div>
        <!-- header -->
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px] mt-[15px]" :inline="true" :model="queryParams">
                <el-form-item label="用户ID搜索">
                    <el-input
                        class="w-[150px] h-[32px]"
                        placeholder="请输入用户ID"
                        v-model="queryParams.uuid"
                        clearable
                    />
                </el-form-item>
				<el-form-item label="用户搜索">
				    <el-input
				        class="w-[150px] h-[32px]"
				        placeholder="请输入手机号/昵称"
				        v-model="queryParams.user_keyword"
				        clearable
				    />
				</el-form-item>
				<el-form-item label="姓名搜索">
				    <el-input
				        class="w-[150px] h-[32px]"
				        placeholder="请输入姓名"
				        v-model="queryParams.name"
				        clearable
				    />
				</el-form-item>
				<el-form-item label="手机号搜索">
				    <el-input
				        class="w-[150px] h-[32px]"
				        placeholder="请输入手机号"
				        v-model="queryParams.phone"
				        clearable
				    />
				</el-form-item>
				<el-form-item label="社区名称搜索">
				    <el-input
				        class="w-[180px] h-[32px]"
				        placeholder="请输入订单号"
				        v-model="queryParams.community_name"
				        clearable
				    />
				</el-form-item>
               <!-- <el-form-item label="到账状态">
                    <el-select
                        placeholder="全部"
                        class="w-[160px] h-[32px]"
                        v-model="queryParams.status"
                    >
                        <el-option label="全部" value="" />
                        <el-option label="已到账" :value="1" />
                        <el-option label="已退款" :value="0" />
                    </el-select>
                </el-form-item> -->
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
			<el-button
			    @click="shenheAll"
			    class="w-[84px] h-[30px] mb-[9px] text-[12px] ml-2"
			    :disabled="ids.length > 0 ? false : true"
			    >一键审核</el-button
			>
            <el-table size="large" class="mt-[14px]" :data="pager.lists" @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="60" />
                <el-table-column label="申请用户ID / 手机号 / 昵称" min-width="210">
                    <template #default="{ row }">
                        {{ row.uuid }} / {{ row.phone }} / {{ row.nickname }}
					</template>
                </el-table-column>
                <el-table-column label="姓名">
                    <template #default="{ row }">
                        <span>{{ row.name }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="手机号" min-width="140">
                    <template #default="{ row }">
                       {{ row.phone }}
                    </template>
                </el-table-column>
                <el-table-column label="社区名称" min-width="120">
                    <template #default="{ row }">
                        <span> {{ row.community_name}}</span>
                    </template>
                </el-table-column>
				<el-table-column label="门头照片" min-width="120">
				    <template #default="{ row }">
				        <el-image
				            style="width: 60px; height: 60px"
				            :src="row.image"
				            :preview-src-list="[row.image]"
				            :hide-on-click-modal="true"
				            :preview-teleported="true"
				            :fit="'cover'"
				        >
				        </el-image>
					</template>
				</el-table-column>
				<el-table-column label="地址信息" min-width="180">
				    <template #default="{ row }">
				        <span> {{ row.address_area}}</span>
				    </template>
				</el-table-column>
				<el-table-column label="详细地址" min-width="160">
				    <template #default="{ row }">
				        <span> {{ row.address}}</span>
				    </template>
				</el-table-column>
                <el-table-column label="创建时间" prop="created_at" min-width="180" />
                <el-table-column label="操作" min-width="160" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            type="primary"
                            link
                            @click="handledel(row.id,1)">
                            通过
                        </el-button>
                        <el-button
                            type="primary"
                            link
                            @click="handledel(row.id,3)">
                            驳回
                        </el-button>
                       
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>

<script lang="ts" setup>
import { usePaging } from '@/hooks/usePaging'
import { communityApplyList, communityApplyBatchExamine,communityApplyExamine } from '@/api/teamhead'
// import { getRoutePath } from '@/router'
import feedback from '@/utils/feedback'

const queryParams = reactive({
    uuid: '',
    user_keyword: '',
    community_name: '',
	name:'',
	phone:''
})
const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: communityApplyList,
    params: queryParams
})
getLists()
const ids = ref<any[]>([])
let dataids:string = '' 
const handleSelectionChange = (val: any[]) => {
	dataids = dataids+val.map((item) => {
        return item.id
    })
    ids.value = val.map((item) => {
        return item.id
    })
  
}
const shenheAll = async () => {
    await feedback.confirm('确定要一键审核？')
    await communityApplyBatchExamine({ community_id: dataids})
    getLists()
}
const handledel = async (id: number,type:number) => {
   await feedback.confirm(type==1?'确定要通过？':'确定要驳回？')
   await communityApplyExamine({ community_id:id,status:type })
   // feedback.msgSuccess('操作成功')
   getLists()
}
</script>
<style lang="scss" scope>
//TODO
.el-alert--warning.is-light {
    background-color: rgba(246, 248, 255, 1);
    color: rgba(64, 115, 250, 1);
}
.text-red {
    color: red;
}
</style>
